/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.spring.modelo.DAO;

import com.spring.modelo.entidad.Carrera;
import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Ricardo
 */
@Repository
public class CarreraDAO extends HibernateDaoSupport{
    
    @Autowired
    public CarreraDAO(SessionFactory sessionFactory) {
        super.setSessionFactory(sessionFactory);
    }
    
    public List<Carrera> getListaCarrera(){
        return getHibernateTemplate().find("select c from Carrera c");
    }
    
    public Carrera buscarCarrera(String codigo){
        System.out.println("....."+codigo);
        return getHibernateTemplate().get(Carrera.class, codigo);
    }
    public boolean insertarCarrera(Carrera c){
        boolean b=false;
        try{
            getHibernateTemplate().saveOrUpdate(c);
            b=true;
        }catch(Exception e){
            e.printStackTrace();
        }
        return b;
    }
    
    @Transactional
    public boolean eliminarCarrera(String codigo){
        boolean b=false;
        try{
            Carrera c=getHibernateTemplate().get(Carrera.class,codigo);
            getHibernateTemplate().delete(c);
            b=true;
        }catch(Exception e){
            b=false;
        }
        return b;
    }
}